#include <iostream>
#include <pthread.h>
#include <string>
#include <vector>
#include <unistd.h>

// int g_val = 0;
// void *pthread_route(void *args)
// {

//     std::cout << "pthread " << "-" << g_val << std::endl;
//     g_val++;
//     return nullptr;
// }

void *threadrun(void *args)
{
    std::string name = static_cast<const char *>(args);
    while (true)
    {
        std::cout << name << " is running" << std::endl;
        sleep(1);
    }
    return nullptr;
}
int main()
{

    std::vector<pthread_t> tids;
    for (int i = 0; i < 10; i++)
    {
        pthread_t tid;
        char name[128];
        sprintf(name, "pthread - %d", i + 1);
        pthread_create(&tid, nullptr, threadrun, name);
    }

    sleep(100);
    // // 创建线程
    // pthread_t tid1;
    // pthread_create(&tid1, nullptr, pthread_route, (void *)"hello, Linux");
    // pthread_t tid2;
    // pthread_create(&tid2, nullptr, pthread_route, (void *)"hello, Linux");
    // pthread_t tid3;
    // pthread_create(&tid3, nullptr, pthread_route, (void *)"hello, Linux");
    // pthread_t tid4;
    // pthread_create(&tid4, nullptr, pthread_route, (void *)"hello, Linux");

    // void **ret1 = nullptr;
    // pthread_join(tid1, ret1);
    // void **ret2 = nullptr;
    // pthread_join(tid2, ret2);
    // void **ret3 = nullptr;
    // pthread_join(tid3, ret3);
    // void **ret4 = nullptr;
    // pthread_join(tid4, ret4);
    return 0;
}